home *** CD-ROM | disk | FTP | other *** search
/ Amiga Collections: Taifun / Taifun 095 (1989-05-15)(Ossowski, Stefan)(DE)(PD).zip / Taifun 095 (1989-05-15)(Ossowski, Stefan)(DE)(PD).adf / KeyKlick / Keyclick.doc < prev    next >
Text File  |  1989-03-31  |  5KB  |  145 lines

  1.  
  2.  
  3.  
  4.                            Keyclick version 1.1
  5.  
  6.  
  7.      One thing I always missed about the Amiga was an audio click when the
  8.  
  9. keys were pressed.  While the Amiga keyboard has the best feel of any I've
  10.  
  11. typed on, it doesn't have a form of audio feedback, which aids in
  12.  
  13. touch-typing.  Thanks to the multitasking operating system however, the
  14.  
  15. addition of such a feature is relatively painless, both from a user's and a
  16.  
  17. programmer's standpoint.
  18.  
  19.      Upon running the program, a window will be presented which contains
  20.  
  21. two gadgets.  The slider is used for adjusting the volume of the click.  The
  22.  
  23. toggle switch can be "pressed" to turn the sound on or off.  After the
  24.  
  25. program is up and running, an audio click will be produced at each press of
  26.  
  27. a key on the keyboard or a mouse button.  You cannot run more than one key
  28.  
  29. clicker at a time; the second clicker that you run will indicate that a
  30.  
  31. key-clicker is already active in the system.  Simply close the window to
  32.  
  33. end the program.  That's about all you have to know as a user.
  34.  
  35.      For you programmers out there...  This program demonstrates custom
  36.  
  37. input handlers and effectively sharing the complicated audio device; two
  38.  
  39. concepts that can be put to great use.
  40.  
  41.      The center of activity revolves around a custom input handler, which
  42.  
  43. simply signals the waiting task when a key or mouse button event arrives in
  44.  
  45. the input stream.  Once the task is awakened, it sends a command to the
  46.  
  47. audio device to initiate the click and goes back to sleep. Therefore, this
  48.  
  49. program only uses a significant amount of processor time when a key or
  50.  
  51. mouse button is actually pressed.
  52.  
  53.      I had the program set its own priority to fourty (this can be changed
  54.  
  55. by assigning a different value to TASK_PRIORITY, defined at the beginning
  56.  
  57. of the program) for better response.  At lower task priority values, the
  58.  
  59. program tended to be sluggish on occasion (especially in a busy system).
  60.  
  61. The input handler priority (defined by HANDLER_PRIORITY) is set at
  62.  
  63. fifty-one.  This causes events from the input stream to be intercepted
  64.  
  65. before Intuition gets ahold of them.  This is desirable because Intuition
  66.  
  67. "swallows" some of the events.  That is, it removes some of them from the
  68.  
  69. input stream, preventing the custom input handler from notifying the
  70.  
  71. clicker task.
  72.  
  73.      At each stroke of a key, an audio channel is allocated, a sound
  74.  
  75. request is issued to the audio device, and the channel previously allocated
  76.  
  77. is freed.  All of this takes place within the click() routine.  After a
  78.  
  79. channel is allocated (via a call to get_audio_channel()), the io_Unit
  80.  
  81. parameter is checked to see if an allocation actually succeeded.  A zero in
  82.  
  83. this parameter indicates that no channel could be allocated.  If this is
  84.  
  85. the case, the click() routine returns immediately without attempting to ask
  86.  
  87. the audio device to make a click sound.  Any other value in io_Unit denotes
  88.  
  89. which channel has been allocated for use.  The IOAudio structure is
  90.  
  91. prepared for a CMD_WRITE to issue a sound request to the audio device, and
  92.  
  93. is executed with a call to BeginIO().  A WaitIO() call is immediately
  94.  
  95. issued after the BeginIO() so the program waits until completion of the
  96.  
  97. write request.  This is needed to delay freeing the channel until the click
  98.  
  99. sound is completed playing (after WaitIO() returns, a call to
  100.  
  101. free_audio_channel() frees the previously allocated audio channel).
  102.  
  103.      An alternate method of audio manipulation would be to allocate an
  104.  
  105. audio channel at the beginning of the program and set it to the highest
  106.  
  107. possible priority (127) to prevent it from being stolen by other tasks
  108.  
  109. requiring audio channels.  However, this method does not take full
  110.  
  111. advantage of the audio device's sophistication; it must be remembered that
  112.  
  113. in a multitasking environment you have to share resources.  Allocating and
  114.  
  115. "holding on" to an audio channel is very uncooperative (and selfish!).
  116.  
  117.      The in-line assembly language at the end of the C source code is an
  118.  
  119. input handler interface, which is required for the system to "communicate"
  120.  
  121. with the custom input handler.  In other words, it copies the appropriate
  122.  
  123. system registers (A0 and A1) to the stack to conform with the input handler
  124.  
  125. calling convention.  This is absolutely essential if the system is to work
  126.  
  127. correctly with the custom input handler.
  128.  
  129.      I would like to hear your comments on this program.  Feel free to
  130.  
  131. E-Mail me on GEnie (MMD) or Delphi (MOCKO).
  132.  
  133.  
  134.      Note- a simplified version of this program (V1.0) can be found in the
  135. November 1988 issue of Amazing Computing.  The program as it appears in
  136. print statically allocates an audio channel, therefore preventing any other
  137. task in the system from allocating (stealing) it.  This version of the
  138. program dynamically allocates an audio channel at a priority of -90 each
  139. time a key is pressed, and works well with other tasks using the audio
  140. device (at least with my experiences).  This version also adds a toggle
  141. switch to enable the user to prevent the program from clicking if so
  142. desired.  If any problems are encountered in using this program, I'd like
  143. to know so I can upload updated versions. Thank you. -Mike
  144.  
  145.